package com.cy.law.utils;

import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import lombok.extern.slf4j.Slf4j;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

@Slf4j
public class IHttpUtil {
    static {
        Properties properties = new Properties();
        InputStream in = IHttpUtil.class.getClassLoader().getResourceAsStream("classpath:application.properties");
        try {
//            properties.load(in);
//            ArtemisConfig.host = properties.getProperty("hk.host");
//            ArtemisConfig.appKey = properties.getProperty("hk.appKey");
//            ArtemisConfig.appSecret = properties.getProperty("hk.appSecret");
            ArtemisConfig.host="134.200.0.20";
            ArtemisConfig.appKey="26952209";
            ArtemisConfig.appSecret="tCTrcGaMH6no3t59Xt8i";
        } catch (Exception e) {
//            e.printStackTrace();
            log.error(e.getMessage(), e);

        }
    }

    private static final String DEVICE_URL = "/api/common/v1/remoteCameraInfoRestService/findCameraInfoPage";
    private static final String UNIT_URL = "/api/common/v1/remoteControlUnitRestService/findControlUnitPage";

    private static final String ARTEMIS_PATH = "/artemis";


    public static String getDevice(int pageIndex, int pageSize) {
        return get(DEVICE_URL, pageIndex, pageSize);
    }

    public static String getUnit(int pageIndex, int pageSize) {
        return get(UNIT_URL, pageIndex, pageSize);
    }

    public static String get(String url, int pageIndex, int pageSize) {
        String u = ARTEMIS_PATH + url;
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("start", pageIndex + "");
        querys.put("size", pageSize + "");
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", u);
            }
        };
        return ArtemisHttpUtil.doGetArtemis(path, querys, null, null);
    }
}
